<?php  

class m_sppd_perjalanan extends CI_Controller {
 
	var $limit=10;
	var $offset=10;	
	
	function index($limit='',$offset=''){
		$this->load->model("init"); 
		$this->init->getLasturl();
		if($this->session->userdata('LOGIN')=='TRUE'){
		$this->load->model("m_sppd_perjalanan_model"); 
		$data['judul']='Master Perjalanan';
		 
		$data['query']=$this->m_sppd_perjalanan_model->getListKota();
		$data['view']='m_sppd_perjalanan/hist_sppd';
		$this->load->view('index',$data);
		}else {
		redirect('home/loginPage');		
		}

	}
	function search($limit='',$offset=''){
	 	$this->load->model("m_sppd_perjalanan_model"); 
		/* VAGINATION */
		if($limit==''){ $limit = 0; $offset=10 ;}
		if($limit!=''){ $limit = $limit ; $offset=$this->offset ;}
		$data['count']=$this->m_sppd_perjalanan_model->count_kota();	
		$config['base_url'] = base_url().'m_sppd_perjalanan/search/';
		$config['total_rows'] = $data['count'];
		$config['per_page'] = $this->limit;    
		$config['cur_tag_open'] = '<span class="pg">';
		$config['cur_tag_close'] = '</span>';		
		$this->pagination->initialize($config);
		/*----------------*/ 
		$data['query']=$this->m_sppd_perjalanan_model->getListKota();
		$this->load->view('m_sppd_perjalanan/data',$data);
	}
	
	function add($id=''){	
		 $this->load->model("m_sppd_perjalanan_model"); 
			$id_combo_asal="";
			$id_combo_tujuan="";
			$id_combo_kendaraan="";
			$harga="";
		 if($id!='0'){
		 $info=$this->m_sppd_perjalanan_model->getdataperjalanan($id);		
			$id_combo_asal=$info->dari;
			$id_combo_tujuan=$info->tujuan;
			$id_combo_kendaraan=$info->id_kendaraan;
			$harga=$info->nominal;
		 }
		 $table="";
		 $table.="<form id='frmsave' name='frmsave'><table style='width:100%;height:100%'>";
		 $table.="<tr>";
		 $table.="<td>Kota Asal</td>";
		 $table.="<td>:</td>";
		 $table.="<td>".$this->m_sppd_perjalanan_model->generateComboAsal($id_combo_asal)."</td>";
		 $table.="</tr>";
		 $table.="<tr>";
		 $table.="<td>Kota Tujuan</td>";
		 $table.="<td>:</td>";
		 $table.="<td>".$this->m_sppd_perjalanan_model->generateComboTujuan($id_combo_tujuan)."</td>";
		 $table.="</tr>";
		  $table.="<tr>";
		 $table.="<td>Kendaraan</td>";
		 $table.="<td>:</td>";
		 $table.="<td>".$this->m_sppd_perjalanan_model->generateComboKendaraan($id_combo_kendaraan)."</td>";
		 $table.="</tr>";
		 $table.="<tr>";
		 $table.="<td>Total Biaya</td>";
		 $table.="<td>:</td>";
		 $table.="<td><input type='text' name='totalharga' id='totalharga' value='".$harga."'></td>";
		 $table.="</tr>";
		 
		 $table.="</table></form>";
		echo $table;
	}
  
	function simpan($id=''){
		if($this->input->post('comboAsal')==''){
		echo "Kota Asal Tidak Boleh Kosong"; return false;
		} else if($this->input->post('comboTujuan')==''){
			echo "Kota Tujuan Tidak Boleh Kosong"; return false;
		} else if($this->input->post('comboKendaraan')==''){
			echo "Jenis Kendaraan Tidak Boleh Kosong"; return false;
		} else if($this->input->post('totalharga')==''){
			echo "Biaya Boleh Kosong"; return false;
		}
		
		$this->load->model("m_sppd_perjalanan_model"); 
		$this->m_sppd_perjalanan_model->simpan($id);
	}
	 
	 
	function deletePerjalanan($id=''){
		$this->db->query("delete from m_sppd_kota where id='$id'");
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */